package com.control;



import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.po.User;
import com.service.UserService;

@Controller
@RequestMapping("/user")
public class UserControl  extends BaseControl{
	@Autowired
	private UserService us;
	
	@RequestMapping("/login")
	public String login(@RequestParam("uname")String uname,@RequestParam("pwd") String pwd){
		System.out.println(us);
		User u = us.findByUname(uname,pwd);
		System.out.println("login..."+uname+"---"+pwd);
		
		session.setAttribute("user", u);
		if(u!= null){
			System.out.println("login...success");
			if(u.getGrade() == 1){
				return "user";
			}else{
				return "jt/jiatiao/getMyWorks";
			}
			//return "success";
		}
		
		return "error";
	}

	@RequestMapping("/reg")
	public String reg(@RequestParam("uname")String uname,@RequestParam("pwd") String pwd){
		boolean u = us.addUser(uname,pwd);
		if(u){
			return "login";
		}
		
		return "error";
	}

}
